import math

miu=3

def caluP0(rou,s):
    sum=0
    for n in range(s):
        sum+=rou**n/math.factorial(n)
    p0=sum+(rou**s/math.factorial(s))*(1/(1-rou/s))
    return math.fabs(1/p0)

def caluWq(daoda,s=7):
    if daoda==0:
        return 0
    else:
        rou=daoda/miu
        p0=caluP0(rou,s)
        rou_=daoda/(s*miu)
        Lq=(daoda**s)*rou_/math.factorial(s)*p0
        Wq=Lq/daoda
        return Wq

import csv
csvfile=open("实际到达率.csv","r")
reader=csv.reader(csvfile)

for i in reader:
    i=float(i[3])
    Wq=caluWq(i)
    print(Wq)

import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei'] # 中文
plt.rcParams['axes.unicode_minus'] = False # 负号

def funImg2D(step=0.03, axisRange=(-10,10)):
    # 计算所有的点
    x=[]
    i=axisRange[0]
    while i<=axisRange[1]:
        x.append(i)
        i+=step
    def calu(x,f):
        y = []
        for xi in x:
            y.append(f(xi))
        return y
    y1 = calu(x, lambda x: caluWq(x))

    fig=plt.figure()
    plt.plot(x, y1) # 在当前的对象上进行操作
    plt.legend()  # 让图例生效
    plt.grid(True) # 显示网格
    plt.xlabel('实际到达率')  # X轴标签
    plt.ylabel('平均等待时间')  # Y轴标签
    plt.show(fig) # 没有输入值默认展示所有对象

funImg2D(1,(4,100))